package o;

import android.content.Context;
import android.net.Uri;
import java.io.Closeable;
import java.io.File;

public class ccl {
    private static String ˋ(Context context) {
        File filesDir = context.getFilesDir();
        if (filesDir == null) {
            return null;
        }
        String str = filesDir.getAbsolutePath() + "/UserIcon/";
        File file = new File(str);
        if (file.exists() || file.mkdirs()) {
            return str;
        }
        return null;
    }

    public static File ˊ(Context context, boolean z) {
        String ˋ = ˋ(context);
        if (ˋ == null) {
            return null;
        }
        File file = new File(ˋ, z ? "user_temp.jpg" : "user.jpg");
        if (file.exists()) {
            bqx.ˊ("HeadIconUtil", "createUserIconFile exists, delete file");
            if (!file.delete()) {
                bqx.ˋ("HeadIconUtil", "createUserIconFile exists, delete failed");
            }
        }
        return file;
    }

    public static boolean ˋ(Context context, Uri uri, Uri uri2) {
        Closeable createOutputStream;
        Throwable th;
        try {
            createOutputStream = context.getContentResolver().openAssetFileDescriptor(uri2, "rw").createOutputStream();
            try {
                Closeable openInputStream = context.getContentResolver().openInputStream(uri);
                byte[] bArr = new byte[16384];
                while (true) {
                    int read = openInputStream.read(bArr);
                    if (read > 0) {
                        createOutputStream.write(bArr, 0, read);
                    } else {
                        dnw.ˎ(openInputStream);
                        dnw.ˎ(createOutputStream);
                        return true;
                    }
                }
            } catch (Exception e) {
                try {
                    bqx.ˋ("HeadIconUtil", "savePhotoFromUriToUri error");
                    dnw.ˎ(null);
                    dnw.ˎ(createOutputStream);
                    return false;
                } catch (Throwable th2) {
                    th = th2;
                    dnw.ˎ(null);
                    dnw.ˎ(createOutputStream);
                    throw th;
                }
            }
        } catch (Exception e2) {
            createOutputStream = null;
            bqx.ˋ("HeadIconUtil", "savePhotoFromUriToUri error");
            dnw.ˎ(null);
            dnw.ˎ(createOutputStream);
            return false;
        } catch (Throwable th3) {
            th = th3;
            createOutputStream = null;
            dnw.ˎ(null);
            dnw.ˎ(createOutputStream);
            throw th;
        }
    }
}
